package com.doubao.contoller;

import com.doubao.entity.SOfferlineMsg;
import com.doubao.nettyhandler.WebSocketHandler;
import com.doubao.pojo.ResponseBean;
import com.doubao.service.ISOfferlineMsgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * description:UserLoginContoller
 * <p>
 * author:sult
 * time: 2018/11/1 17:23
 **/
@RestController
@RequestMapping("user")
public class UserContoller {

    private static final Logger log = LoggerFactory.getLogger(UserContoller.class);

    @Autowired
    private ISOfferlineMsgService iSOfferlineMsgService;

    @GetMapping("/getOfferlineMsg")
    public ResponseBean getOfferlineMsg(HttpServletRequest request){
        String from = request.getParameter("from");
        String to = request.getParameter("to");
        log.info("查询未读消息入参[from:{},to:{}]",from,to);
        if(StringUtils.isEmpty(from)||StringUtils.isEmpty(to)){
            return  new ResponseBean("参数有误！","500");
        }
        try {
            List<SOfferlineMsg> list =iSOfferlineMsgService.getOfferlineMsg(from,to);
            if(list.size()>0){
                List<String> result = new ArrayList<>();
                for(SOfferlineMsg s:list){
                    result.add(s.getContent());
                }
                return new ResponseBean().setSucess().setData(result);
            }
            return new ResponseBean().setSucess();
        } catch (Exception e) {
            e.printStackTrace();
            return  new ResponseBean("查询出错了！","500");
        }
    }

}
